package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.queryparam.NursingPlanQueryParam;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划管理有关接口")
public class NursingPlanController {

    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 分页查询
     *
     * @param npqp
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("分页查询护理计划")
    public ResponseResult<PageResponse<NursingPlanVo>> getPage(NursingPlanQueryParam npqp) {
        PageResponse<NursingPlanVo> result = nursingPlanService.getPage(npqp);

        //log.info("数据库查询的数据:{}",result);
        return ResponseResult.success(result);
    }

    /**
     * 新增护理计划
     *
     * @param npd
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto npd) {

        nursingPlanService.addNursingPlan(npd);

        return ResponseResult.success();
    }

    /**
     * 回显
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult getByIdNursingPlan(@PathVariable Long id) {

        NursingPlanVo npv = nursingPlanService.getByIdNursingPlan(id);

        return ResponseResult.success(npv);
    }

    /**
     * 修改护理计划
     *
     * @return
     */
    @PutMapping("{id}")
    @ApiOperation("修改护理计划")
    public ResponseResult updateNursingPlan(@RequestBody NursingPlanDto npd) {

        nursingPlanService.updateNursingPlan(npd);

        return ResponseResult.success();
    }

    /**
     * 启用禁用
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理计划")
    public ResponseResult statusNursingPlan(@PathVariable Integer id, @PathVariable Integer status) {

        nursingPlanService.statusNursingPlan(id, status);

        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult deleteNursingPlan(@PathVariable Integer id) {

        nursingPlanService.deleteNursingPlan(id);

        return ResponseResult.success();
    }

    /**
     * 查询所有护理计划
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult allList() {

        List<NursingPlanVo> npvList = nursingPlanService.allList();

        return ResponseResult.success(npvList);
    }
}
